package ch.usi.inf.pf2.editor;

import ch.usi.inf.pf2.Sheet;

/**
 * MultipleCopy is useful to copy more cells.
 * 
 * @author Lorenzo Baracchi <lorenzo.baracchi@usi.ch>
 */
public class MultipleCopy extends MultipleTextManagement
{
    Copy[][] toCopy;
    
    
    /**
     * Create a Copy of more cells.
     * @param s The sheet where the multiple copying is performed.
     * @param rowIndexes The rows of the selected cells.
     * @param columnIndexes The columns of the selected cells.
     */
    public MultipleCopy (Sheet s, int[] rowIndexes, int[] columnIndexes)
    {
	   toCopy=new Copy[rowIndexes.length][columnIndexes.length];
	   for(int i=0; i<rowIndexes.length; i++)
		  for(int j=0; j<columnIndexes.length; j++)
			 toCopy[i][j]=new Copy(s, rowIndexes[i]+1, columnIndexes[j]+1); 
    }
    
    
    /**
     * Apply the copy action to all the selected cells.
     */
    public void evaluate()
    {
	   for(int i=0; i<toCopy.length; i++)
		  for(int j=0; j<toCopy[i].length; j++)
			 toCopy[i][j].evaluate();
    }
    
    /**
     * Restore the previous contents of the copied cells.
     */
    public void restore()
    {
	   for(int i=0; i<toCopy.length; i++)
		  for(int j=0; j<toCopy[i].length; j++)
			 toCopy[i][j].restore();
    }

    
    @Override
    public TextManagement[][] getActions()
    {
	   return toCopy;
    }
}
